home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: newshub.nosc.mil!news!herman
- From: herman@nosc.mil (John W. Herman)
- Subject: Re: Handling complex numbers...
- Message-ID: <1996Mar11.204246.7444@nosc.mil>
- Sender: news@nosc.mil
- Organization: NCCOSC RDT&E Division, San Diego, CA
- References: <4hi113$2i8k@mercury.cc.uottawa.ca> <larry_kearney-0803960747220001@amaryllisp1.appsig.com>
- Date: Mon, 11 Mar 1996 20:42:46 GMT
-
- larry_kearney@appsig.com (Larry Kearney) writes:
-
- >> Dear fellow netters,
- >>
- >> Can someone kindly explain to me how to represent complex numbers in C?
- >> I am writing a numerical method program to calculate the area under
- >> a curve using Simpson's Rule. The problem that I face right now is
- >> the representation of "i" (where i^2 = -1) in my C program.
- >>
- >> Here's a simple example of what I mean:
- >>
- >> _b
- >> |
- >> | exp(ix) dx
- >> _|
- >> a
- >>
- >>
- >> How do I implement this function exp(ix)?
- >>
- >> I'm grateful for your help.
- >>
- >> Charles Tran
- >> --
- >> Charles
-
- >The C language is not terribly efficient when it comes to complex numbers.
- >You can represent a complex number as a struct, i.e.,
-
- >typedef struct
- >{
- > double re; /* real part of the complex number */
- > double im; /* imaginary part of the complex number */
- >} complex;
-
- >but the big problem is that the arithmetic operators don't know what to do
- >when presented with values that are structures. As a result, the
- >programmer is required to implement functions that perform that standard
- >operations and that take complex structs as arguments. For example,
-
- >void AddComplex ( complex *a, complex *b, complex *c )
- *** Stuff deleted ***
-
- There are also macros for these problems which generate more effecient code.
- These have been posted several times before.
-